package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.model.UnlockRecord;
import com.yami.shop.dao.UnlockRecordMapper;
import com.yami.shop.service.UnlockRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 解锁记录 服务实现类
 * </p>
 *
 * @author chajiu
 * @since 2021-06-29
 */
@Service
public class UnlockRecordServiceImpl extends ServiceImpl<UnlockRecordMapper, UnlockRecord> implements UnlockRecordService {

    @Override
    public boolean isUnlocked(String fromId, String toId) {

        //是否已解锁该用户
        int count = count(Wrappers.lambdaQuery(new UnlockRecord())
                .eq(UnlockRecord::getFromUserId, fromId)
                .eq(UnlockRecord::getUnlockedUserId, toId)
                .eq(UnlockRecord::getStatus, 1));
        if (count > 0) {
            return true;
        } else {
            return false;
        }
    }
}
